package com.yan.common.mq.dirct;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * Created by yanl_ on 2018/4/17.
 * https://blog.csdn.net/olinner123/article/details/77477323
 *
 * 使用Message传递参数的坑在于@RabbitListener放在方法上，放在类上则
 * Caused by: org.springframework.amqp.AmqpException: No method found for class [B
 */
@Component

public class DirctReceiverB {

    @RabbitListener(queues = "test2")
    @RabbitHandler
    public void getMessage(Message message) {
        try {

            String msg = new String(message.getBody(), "utf-8");
            System.out.println("Receiver  spring-boot-queue_2 ==================: " + message
           +"  " +msg);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }


    }


}
